<template>
  <div>
    <headerTop></headerTop>
    <headerMin @search="searchInit"></headerMin>
    <!-- 主体 -->
    <div class="allGoods">
      <!-- 索引 -->
      <div class="indexes wrap">
        <span class="c1" @click="Goindex()">首页></span>
        <span v-if="List1.state == 1">> {{List1.title}}</span>
      </div>
      <div class="content wrap bgw">
        <!-- 索引列表 -->
        <div class="indexesList fl">
          <div
            :class="{active1:activeType1 == i}"
            @click="NavTab1(v.id,i)"
            v-for="(v,i) in classTitle"
            :key="i"
            class="title"
          >
            {{v.category_name}}
            <img
              class="fr"
              src="@/assets/image/Listofcommodities_Open_icon@2x.png"
              alt
            />
            <div
              v-show="activeType1 ==i"
              @click.stop
              @click="NavTab2(a.id,b)"
              v-for="(a,b) in v.childData"
              :key="b"
              class="list"
            >
              <p class="one">
                <img
                  v-if="activeType2 !=b"
                  src="@/assets/image/Listofcommodities_plus_icon@2x.png"
                  alt
                />
                <img
                  v-if="activeType2 ==b"
                  src="@/assets/image/Listofcommodities_reduce_icon@2x.png"
                  alt
                />
                {{a.category_name}}
              </p>
              <div class="txt">
                <p
                  v-show="activeType2 == b"
                  @click.stop
                  @click="NavTab3(c.id)"
                  v-for="(c,d) in a.childData"
                  :key="d"
                  class="one"
                >{{c.category_name}}</p>
              </div>
            </div>
          </div>
        </div>
        <!-- 商品列表 -->
        <div class="goodsList fr">
          <div class="pageTop">
            <span>1</span>/50
            <img src="@/assets/image/Listofcommodities_Left_icon@2x.png" alt />
            <img src="@/assets/image/Listofcommodities_right_icon@2x.png" alt />
          </div>
          <!-- 商品详情 -->
          <div v-if="List1.state == 0 && activeType1 == -1" class="noneSearch">
            抱歉，没有找到与 "
            <span>{{List1.title}}</span> " 相关的内容
          </div>

          <div
            @click="GoGoodsDetails(v)"
            :key="i"
            v-for="(v,i) in goodsList"
            class="all_goodsDetails"
          >
            <div class="img_BOx">
              <img :src="v.goods_img" alt />
            </div>
            <p class="one">￥{{v.price}}</p>
            <p class="two">{{v.goods_name}}</p>
            <p class="one">
              评论
              <span>{{v.commentSum}}</span>
              条
            </p>
            <button @click="GoGoodsOrder()">立即购买</button>
          </div>
        </div>
      </div>
    </div>
    <div class="bg1">
      <publicBottom></publicBottom>
    </div>
  </div>
</template>
<script>
import headerTop from "@/components/public/public_headerTop.vue";
import headerMin from "@/components/index/index_header_min";
import publicBottom from "@/components/public/public_bottom";

import { getAllCate } from "@/request/index"; //所有分类
import { Goods_indexs } from "@/request/index"; // 获取 分类或搜索的商品列表
export default {
  components: {
    headerTop,
    headerMin,
    publicBottom
  },
  data() {
    return {
      searchState: 0,
      classTitle: [], //索引 列表
      goodsList: [], // 商品列表
      List1: [], //搜索 列表
      activeType1: 1,
      activeType2: 0,
      id: 0
    };
  },
  mounted() {
    this.start();
    let msg = this.$route.query.search;
    if (msg == undefined) {
      this.allGoods();
    } else {
      this.activeType1 = -1;
    }
  },
  methods: {
    searchInit(e) {
      this.List1 = e;
      if (e.state == 1) {
        if (e.data.goods_list != "") {
          this.goodsList = e.data.goods_list;
        }
      }
    },
    Goindex() {
      this.$router.replace({ path: "/" });
    },
    NavTab1(id, i) {
      this.id = id;

      if (this.activeType1 == i) {
        this.activeType1 = -1;
      } else {
        this.activeType1 = i;
      }
      this.allGoods();
    },
    NavTab2(id, i) {
      console.log(i);

      this.id = id;
      if (this.activeType2 == i) {
        this.activeType2 = -1;
      } else {
        this.activeType2 = i;
      }
      this.allGoods();
    },
    GoGoodsOrder() {
      this.$router.push({ path: "/goodsOrder?id=" + this.goods.id });
    },
    start() {
      getAllCate().then(res => {
        this.classTitle = res.data;
        this.id = res.data[0].id;
      });
    },
    GoGoodsDetails(e) {
      this.$router.push({ path: "/goodsDetails?id=" + e.id });
    },
    allGoods() {
      let shopId = localStorage.getItem("lzyyShopId");
      Goods_indexs({
        shop_id: shopId,
        category_id: this.id,
        keyword: "",
        page: 1
      }).then(res => {
        this.goodsList = res.data.data;
      });
    }
  }
};
</script>
<style lang="less" scoped>
//  全部商品页面
.allGoods {
  // 索引
  .indexes {
    height: 44px;
    line-height: 44px;
    font-size: 14px;
  }
  //   没有搜索内容
  .noneSearch {
    padding-top: 40px;
    width: 1000px;
    font-size: 24px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #333333;
    text-align: center;
    span {
      color: red;
    }
  }
  .content {
    overflow: hidden;
  }

  // 索引列表
  .indexesList {
    width: 192px;

    .title {
      background: #dddddd;
      line-height: 40px;
      position: relative;
      min-height: 40px;
      text-indent: 12px;

      > img {
        width: 6px;
        height: 10px;
        vertical-align: middle;
        margin-top: 14px;
        margin-right: 12px;
      }
    }

    .list {
      min-height: 32px;
      line-height: 32px;
      text-indent: 12px;
      background: rgba(245, 245, 245, 1);
      border: 1px solid rgba(221, 221, 221, 1);

      img {
        width: 12px;
        height: 12px;
        // vertical-align: middle;
        margin-right: 4px;
      }
    }

    .txt {
      text-indent: 12px;
      background: white;
      border: 1px solid rgba(221, 221, 221, 1);

      p {
        line-height: 30px;
      }
    }
  }

  // 页码
  .pageTop {
    width: 100%;
    height: 40px;
    position: relative;
    text-align: right;
    background: rgba(245, 245, 245, 1);
    border: 1px solid rgba(230, 230, 230, 1);
    margin-bottom: 10px;
  }

  // 商品 列表
  .goodsList {
    padding-bottom: 40px;
    display: flex;
    flex-wrap: wrap;
    width: 1000px;
  }

  // 商品详情
  .all_goodsDetails {
    width: 250px;
    height: 418px;
    background: rgba(255, 255, 255, 1);
    border: 1px solid rgba(204, 204, 204, 1);
    box-shadow: 0px 4px 5px 0px rgba(0, 0, 0, 0.1);
    font-size: 16px;
    margin-bottom: 40px;

    .img_BOx {
      width: 100%;
      height: 248px;
    }

    img {
      width: 100%;
      height: 248px;
    }

    p {
      padding-left: 10px;
    }

    span {
      color: #f00000;
    }

    p:nth-of-type(1) {
      font-size: 24px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: rgba(240, 0, 0, 1);
      margin-bottom: 6px;
      margin-top: 4px;
    }

    p:nth-of-type(2) {
      height: 37px;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: rgba(51, 51, 51, 1);
      line-height: 20px;
      margin-bottom: 10px;
    }

    p:nth-of-type(3) {
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: rgba(51, 51, 51, 1);
      line-height: 20px;
      margin-bottom: 10px;
    }

    button {
      width: 208px;
      height: 32px;
      background: rgba(240, 0, 0, 1);
      border-radius: 4px;
      margin: auto;
      display: block;
    }
  }
}

.active1 {
  > img {
    transform: rotate(90deg);
  }
}
</style>